#!/usr/bin/perl

$WORKDIR= $ARGV[0];
$LEGODIR= $ARGV[1];

print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo "#! /bin/sh" > "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Would you like to know what files Uninstall_LEGO_NXT.sh will remove? (Y/N)\" ; read ans' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'case \"\$ans\" in' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   y*|Y*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"To uninstall LEGO MINDSTORMS NXT, you may run this shell script file (\\\"Uninstall_LEGO_NXT.sh\\\")"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"from a Terminal shell.  The shell script removes files from top-level directories and down.  \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Any important, user-defined files should be saved or moved into another location.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Or, you may manually remove (delete) the files and folders listed.  Installed \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"directories are listed below:\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Files to remove for LEGO MINDSTORMS NXT: \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"----------------------------------- \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"$LEGODIR/LEGO MINDSTORMS NXT/...\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/Mindstorms*Ret.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/Mindstorms.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsDut.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsEng.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsFra.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsGer.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsJpn.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'esac' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Would you like to continue uninstalling LEGO MINDSTORMS NXT? (Y/N)\" ; read ans' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'case "\$ans" in' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   n*|N*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   echo \"Uninstallation canceled.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   exit 0 ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   y*|Y*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Proceeding with uninstallation.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Uninstalling LEGO MINDSTORMS NXT...\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -rf \"$LEGODIR/LEGO MINDSTORMS NXT\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/Mindstorms*Ret.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/Mindstorms.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsDut.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsEng.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsFra.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsGer.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsJpn.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsDynamicBlockUpdate.pkg' >> "$LEGODIR/LEGO MINDSTORMS Edu NXT/Uninstall_LEGO_Edu_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Uninstallation complete.\";;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   *)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   echo \"Uninstallation canceled.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   exit 0 ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'esac' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;

print `sudo chmod 755 "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;

my	$results= `uname -p`;

chomp($results);

if ($results eq "powerpc") {
	print `sudo installer -pkg "$WORKDIR/../MindstormsPPCRet.pkg" -target /`;
	print `sudo installer -pkg "$WORKDIR/../MindstormsEngPPCRet.pkg" -target /`; 

	}
else {
	print `sudo installer -pkg "$WORKDIR/../Mindstormsi386Ret.pkg" -target /`; 
	print `sudo installer -pkg "$WORKDIR/../MindstormsEngi386Ret.pkg" -target /`; 
	}

	print `sudo cp -R -f -p "/private/tmp/LEGO MINDSTORMS NXT" "$LEGODIR"`;
	print `sudo rm -R -f "/private/tmp/LEGO MINDSTORMS NXT"`;
	print `sudo rm -f "/$LEGODIR/LEGO MINDSTORMS NXT/engine/BogusSizeFile"`;

